import React, {Component} from 'react';
import isShowStore from '../../stores/IsShowStore';
import IsShowAction from '../../action/IsShowAction';

let isShowAction = new IsShowAction();

class IsShow extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false
        };
        this.click = this.click.bind(this);
        this._onChange = this._onChange.bind(this);
    }

    componentDidMount() {
        isShowStore.addChangeListener(this._onChange)
    }

    componentWillUnmount() {
        isShowStore.removeChangeListener(this._onChange)
    }

    _onChange() {
        this.setState({
            visible: isShowStore.getIsShow()
        })
    }


    click() {
        let visible = !this.state.visible;
        isShowAction.changeIsShow(visible);
    }

    render() {
        let {visible} = this.state;
        return (
            <div>
                <button onClick={this.click}>测试</button>
                {visible ? <div>11</div> : ''}
            </div>
        );
    }
}

export default IsShow;